package main

import (
	"fmt"
	"math/rand/v2"
)

// hw1
func numCombo(nums []int) {
	for i := 0; i < len(nums); i++ {
		for j := 0; j < len(nums); j++ {
			if j == i {
				continue
			}
			for k := 0; k < len(nums); k++ {
				if k == j || k == i {
					continue
				}
				fmt.Printf("%d%d%d\n", nums[i], nums[j], nums[k])
			}
		}
	}
}

// hw2
func letterCombo() string {
	const letters = "abcdefghijklmnopqrstuvwxyz"
	letsLength := rand.IntN(10) + 3
	lets := make([]byte, letsLength)
	for i := 0; i < letsLength; i++ {
		lets[i] = letters[rand.IntN(len(letters))]
	}
	return string(lets)
}

func reverseStr(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

// hw3
func strCombo(s1, s2 string) string {
	var str []byte
	len1, len2 := len(s1), len(s2)
	minlen := minLen(len1, len2)
	for i := 0; i < minlen; i++ {
		str = append(str, s1[i], s2[i])
	}
	if len1 > minlen {
		str = append(str, s1[minlen:]...)
	} else if len2 > minlen {
		str = append(str, s2[minlen:]...)
	}
	return string(str)
}

func minLen(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	numCombo([]int{1, 2, 3, 4}) // hw1
	fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
	str := letterCombo()  //hw2
	restr := reverseStr(str)
	fmt.Printf("%v %v\n", str, restr)
	fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
	fmt.Println(strCombo("abc", "xyz"))  //hw3
	fmt.Println(strCombo("ab", "xyz"))
	fmt.Println(strCombo("abcd", "xy"))
}
